package com.chenfan.mcn.enums;

import com.chenfan.common.extension.dict.DictTranslator;
import lombok.Getter;

import java.util.Objects;

/**
 * 公共结算状态
 * @Author liuyang
 * @Date 2021/6/11
 * @Time 15:01
 * @Version V1.0
 **/
public enum CommonSettleStatusEnum implements DictTranslator<Integer, String> {
    /**
     * 结算状态
     */
    UNSETTLED(0, "未结算"),
    IN_SETTLEMENT(1, "结算中"),
    SETTLED(2, "已结算");

    @Getter
    private final int code;
    @Getter
    private final String statusName;

    CommonSettleStatusEnum(int code, String statusName) {
        this.code = code;
        this.statusName = statusName;
    }

    public int code() {
        return this.code;
    }

    public static String getStatusName(Integer code) {
        if(Objects.isNull(code)) {
            return null;
        }
        for (CommonSettleStatusEnum status : CommonSettleStatusEnum.values()) {
            if (status.code == code.intValue()) {
                return status.statusName;
            }
        }
        return null;
    }


    public static boolean isUnsettled(Integer code) {
        if(Objects.isNull(code)) {
            return false;
        }
        return CommonSettleStatusEnum.UNSETTLED.code == code.intValue();
    }

    public static boolean isSettled(Integer code) {
        if(Objects.isNull(code)) {
            return false;
        }
        return CommonSettleStatusEnum.SETTLED.code == code.intValue();
    }

    @Override
    public String translate(Integer code) {
        return Objects.nonNull(code) ? getStatusName(code) : null;
    }
}
